import dayjs from 'dayjs';

export const formatDate = (date: Date) => {
  return date instanceof Date
    ? dayjs(date).format('YYYY-MM-DD HH:mm:ss')
    : date;
};

/**
 * 根据秒统计日时分秒
 * @param seconds 秒数
 * @returns
 */
export const convertSecondsToTime = (seconds: number) => {
  // 计算天数、小时数、分钟数和秒数
  const days = Math.floor(seconds / (24 * 60 * 60));
  const hours = Math.floor((seconds % (24 * 60 * 60)) / (60 * 60));
  const minutes = Math.floor((seconds % (60 * 60)) / 60);
  const secs = Math.floor(seconds % 60);
  return {
    days,
    hours,
    minutes,
    secs,
  };
};
